Maison  >  Article  >  développement back-end  >  La différence de syntaxe (partie) entre php et python

La différence de syntaxe (partie) entre php et python

PHP中文网
PHP中文网original
2016-03-30 17:08:2614026parcourir

Ce chapitre présentera certaines des différences grammaticales entre php et python. Il a une certaine valeur de référence. Les amis dans le besoin peuvent s'y référer.

Syntaxe hérédoc

php
$a = <<< str
    字符串
    字符串
str;

python
print("""
  字符串
  字符串
""")

Contrôle de la casse des caractères

//php  
(strtolower(str),strtoupper(str))$a = "Hello World";print(strtolower($a));

//python  
(str.lower(), str.upper())a = "Hello World"print(a.lower())

Encodage :

PHP :

header(&#39;content-type:text/html;charset=utf-8&#39;);

Python :

#encoding=utf-8 ou # coding:utf-8 Afin de mettre en valeur le grand talent artistique des programmeurs, il est souvent écrit comme # -*- coding:utf-8 -*- La valeur par défaut de python3 est utf-8

Opération de tableau :

Créer un tableau

PHP:
$array = new array();
或 
$array = array("a"=>"A","b"=>"B");
 Python:
array = []
或
array = [1,2,3]

Ajouter un tableau

PHP :

array_push($arr, $val);

Python :

array.append(val) #追加
或
array.extend(val) #合并

Supprimer un élément du tableau

PHP :

array_pop(); 删除最后一个元素 
array_shift();删除第一个元素

Python :

array.pop()
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Article précédent:Comment configurer PHPArticle suivant:Comment configurer PHP